/**
 * 主题Hook
 */
import { computed } from 'vue';
import { THEMES } from '@/config';
import { useAppStore } from '@/store';
import type { Theme } from '@/types';

export function useTheme() {
  const appStore = useAppStore();

  // 当前主题
  const theme = computed(() => appStore.theme);

  // 是否为亮色主题
  const isLightTheme = computed(() => theme.value === THEMES.LIGHT);

  // 是否为暗色主题
  const isDarkTheme = computed(() => theme.value === THEMES.DARK);

  // 设置主题
  const setTheme = (newTheme: Theme) => {
    appStore.setTheme(newTheme);
  };

  // 切换主题
  const toggleTheme = () => {
    appStore.toggleTheme();
  };

  return {
    theme,
    isLightTheme,
    isDarkTheme,
    setTheme,
    toggleTheme,
  };
}
